/*
 * biller.h
 *
 *  Created on: Dec 18, 2013
 *      Author: killerg
 */

#ifndef BILLER_H_
#define BILLER_H_

#include "share/session_mgr.h"
#include "share/db_mgr.h"
#include "share/sb_msg.pb.h"

struct client_session_t;

struct player_created_t {
    string account;
    string playername;
    int playerid;
};

struct bill_session_t : public cli_session_t<sb::BMsg, sb::BMsgID_ARRAYSIZE> {
    typedef cli_session_t<sb::BMsg, sb::BMsgID_ARRAYSIZE> base;

    bool init();
    void destroy();
    void update();

    db_mgr_t db;
    std::string addr;
    bool authed = false;
    double ping_timer=0.0f;
    list<player_created_t*> need_sync;

    void on_create_player(const string &account, const string &playername, int32_t playerid);
    void use_code(client_session_t* sess, const string &code);

    struct code_proto_t {
        std::string code;
        int32_t reward;
        int32_t mask;
    };

    std::unordered_map<std::string, code_proto_t> code_map;
    int log_fd = -1;
    void log_order(const char* orderid, const char* account, const char* player, double fee, const char* status);
    void log_code(const char* code, const char* account, const char* player, const char* status);

    void dblog_order(const char* orderid, const char* mc, const char* account, const char* player, double fee, time_t create_time);
};

#endif /* BILLER_H_ */
